<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="网点编号" prop="bankCode">
        <el-input v-model="queryParams.bankCode" placeholder="请输入网点编号" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="网点名称" prop="bankName">
        <el-input v-model="queryParams.bankName" placeholder="请输入网点名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="网点类型" prop="bankType">
        <el-select v-model="queryParams.bankType" placeholder="请选择网点类型" clearable>
          <el-option v-for="dict in bank_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="网点状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择网点状态" clearable>
          <el-option v-for="dict in bank_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="上线日期" style="width: 308px">
        <el-date-picker v-model="daterangeOnlineDate" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="联系人" prop="contactPerson">
        <el-input v-model="queryParams.contactPerson" placeholder="请输入联系人" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="联系电话" prop="contactPhone">
        <el-input v-model="queryParams.contactPhone" placeholder="请输入联系电话" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="网点地址" prop="address">
        <el-input v-model="queryParams.address" placeholder="请输入网点地址" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="休息时间" prop="restTime">
        <el-select v-model="queryParams.restTime" placeholder="请选择休息时间" clearable>
          <el-option v-for="dict in rest_time" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="停用日期" style="width: 308px">
        <el-date-picker v-model="daterangeOfflineDate" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="暂停日期" prop="suspendDate">
        <el-date-picker clearable v-model="queryParams.suspendDate" type="date" value-format="YYYY-MM-DD"
          placeholder="请选择暂停日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="合署日期" prop="coLocationDate">
        <el-date-picker clearable v-model="queryParams.coLocationDate" type="date" value-format="YYYY-MM-DD"
          placeholder="请选择合署日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="所属机构" prop="orgId">
        <el-select v-model="queryParams.orgId" placeholder="请选择机构" clearable>
          <el-option v-for="item in allOrganizations" :key="item.id" :label="item.orgName" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="三级机构" prop="parentBankId">
        <el-input v-model="queryParams.parentBankId" placeholder="请输入三级机构" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="扫描标记" prop="scanFlag">
        <el-select v-model="queryParams.scanFlag" placeholder="请选择扫描标记" clearable>
          <el-option v-for="dict in scan_flag" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="省" prop="province">
        <el-select v-model="queryParams.province" placeholder="请选择省份或直辖市" @change="handleProvinceChange" clearable>
          <el-option v-for="item in regionData" :key="item.label" :label="item.label" :value="item.label" />
        </el-select>
      </el-form-item>

      <el-form-item label="市" prop="city">
        <el-select v-model="queryParams.city" placeholder="请选择城市"
          @change="(city) => handleCityChange(queryParams.province, city)" clearable>
          <el-option v-for="item in cityOptions" :key="item.label" :label="item.label" :value="item.label" />
        </el-select>
      </el-form-item>
      <el-form-item label="区" prop="region">
        <el-select v-model="queryParams.region" placeholder="请选择区域" clearable>
          <el-option v-for="item in regionOptions" :key="item.label" :label="item.label" :value="item.label" />
        </el-select>
      </el-form-item>
      <el-form-item label="网点费用属性" prop="feeAttribute" label-width="100px">
        <el-select v-model="queryParams.feeAttribute" placeholder="请选择网点费用属性" clearable>
          <el-option v-for="dict in fee_attribute" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['service:bank:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate"
          v-hasPermi="['service:bank:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleEnable"
          v-hasPermi="['service:bank:edit']">启用</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handlePause"
          v-hasPermi="['service:bank:edit']">暂停</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleDisable"
          v-hasPermi="['service:bank:edit']">停用</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" @click="handleDisable"
          v-hasPermi="['service:bank:edit']">批量导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Upload" @click="handleDelete"
          v-hasPermi="['service:bank:remove']">导入模板</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Edit" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['service:bank:remove']">PDA进入网点密码</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Edit" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['service:bank:remove']">批量修改地区</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Edit" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['service:bank:remove']">设置预约送箱日期</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Edit" @click="handleDelete"
          v-hasPermi="['service:bank:remove']">导出网点信息</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" @click="handleDelete"
          v-hasPermi="['service:bank:remove']">下载电子授权</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" @click="handleDelete"
          v-hasPermi="['service:bank:remove']">上传电子授权</el-button>
      </el-col>
    </el-row>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleEnable"
          v-hasPermi="['service:bank:edit']">批量启用</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handlePause"
          v-hasPermi="['service:bank:edit']">批量暂停</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleDisable"
          v-hasPermi="['service:bank:edit']">批量停用</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleDisable"
          v-hasPermi="['service:bank:edit']">批量修改网点费用属性</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleDisable"
          v-hasPermi="['service:bank:edit']">修改押运物品信息</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleDisable"
          v-hasPermi="['service:bank:edit']">导入押运物品信息</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleDisable"
          v-hasPermi="['service:bank:edit']">押运物品信息导入模版</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['service:bank:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport"
          v-hasPermi="['service:bank:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bankList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="网点编号" align="center" prop="bankCode" width="150px" />
      <el-table-column label="网点名称" align="center" prop="bankName" width="200px" show-overflow-tooltip />
      <el-table-column label="简称" align="center" prop="shortName" width="120px" />
      <el-table-column label="网点地址" align="center" prop="address" width="200px" show-overflow-tooltip />
      <el-table-column label="联系人" align="center" prop="contactPerson" />
      <el-table-column label="联系人电话" align="center" prop="contactPhone" width="120px" />
      <el-table-column label="网点类型" align="center" prop="bankType">
        <template #default="scope">
          <dict-tag :options="bank_type" :value="scope.row.bankType" />
        </template>
      </el-table-column>
      <el-table-column label="地区" align="center" prop="areaId" width="200px" show-overflow-tooltip>
        <template #default="scope">
          <span>{{areaList.find(item => item.id == scope.row.areaId)?.districtComb || ''}}</span>
        </template>
      </el-table-column>
      <el-table-column label="网点状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="bank_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="所属机构" align="center" prop="parentOrgName" width="180px"/>
      <el-table-column label="二级机构" align="center" prop="subOrgName" width="200px"/>
      <el-table-column label="三级机构" align="center" prop="parentBankId" width="150px" />
      <el-table-column label="休息时间" align="center" prop="restTime">
        <template #default="scope">
          <dict-tag :options="rest_time" :value="scope.row.restTime" />
        </template>
      </el-table-column>
      <el-table-column label="钱安达钥匙数量" align="center" prop="qianAndaKey" />
      <el-table-column label="枪柜钥匙数量" align="center" prop="gunCabinetKey" />
      <el-table-column label="交行车辆通行卡" align="center" prop="commCardBank" />
      <el-table-column label="扫描标记" align="center" prop="scanFlag">
        <template #default="scope">
          <dict-tag :options="scan_flag" :value="scope.row.scanFlag" />
        </template>
      </el-table-column>
      <el-table-column label="网点费用属性" align="center" prop="feeAttribute">
        <template #default="scope">
          <dict-tag :options="fee_attribute" :value="scope.row.feeAttribute" />
        </template>
      </el-table-column>
      <el-table-column label="特殊黑袋数量" align="center" prop="otherboxNum" />
      <el-table-column label="预约送箱日期" align="center" prop="appointDeliveryDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.appointDeliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上线日期" align="center" prop="onlineDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.onlineDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="暂停日期" align="center" prop="suspendDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.suspendDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="停用日期" align="center" prop="offlineDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.offlineDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合署日期" align="center" prop="coLocationDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.coLocationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否扫描中调箱" align="center" prop="isScanMidbox" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建日期" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改网点管理对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="bankRef" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="网点名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入网点名称" />
        </el-form-item>
        <el-form-item label="简称" prop="shortName">
          <el-input v-model="form.shortName" placeholder="请输入简称" />
        </el-form-item>
        <el-form-item label="网点地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入网点地址" />
        </el-form-item>
        <el-form-item label="联系人" prop="contactPerson">
          <el-input v-model="form.contactPerson" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="网点类型" prop="bankType">
          <el-select v-model="form.bankType" placeholder="请选择网点类型">
            <el-option v-for="dict in bank_type" :key="dict.value" :label="dict.label"
              :value="parseInt(dict.value)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属区域" prop="areaId">
          <el-select v-model="form.areaId" placeholder="请选择所属机构" clearable>
            <el-option v-for="area in areaList" :key="area.id" :label="area.districtComb" :value="area.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="所属机构" prop="orgId">
          <el-cascader v-model="form.orgId" :options="organizationOptions" :props="cascaderProps" placeholder="请选择上级机构"
            clearable filterable style="width: 100%">
          </el-cascader>
        </el-form-item>
        <el-form-item label="三级机构id" prop="parentBankId">
          <el-input v-model="form.parentBankId" placeholder="请输入三级机构id" />
        </el-form-item>
        <el-form-item label="网点经纬度" prop="locateLat">
          <el-input v-model="form.locateLat" placeholder="请输入位置经度" />
        </el-form-item>

        <el-form-item label="" prop="location">
          <el-button type="primary" @click="getCoordinates">获取经纬度</el-button>
        </el-form-item>
        <el-form-item label="休息时间" prop="restTime">
          <el-select v-model="form.restTime" placeholder="请选择休息时间">
            <el-option v-for="dict in rest_time" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上线日期" prop="onlineDate">
          <el-date-picker clearable v-model="form.onlineDate" type="date" value-format="YYYY-MM-DD"
            placeholder="请选择上线日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 地图选择对话框 -->
    <el-dialog title="选择地图位置" v-model="mapDialogVisible" width="800px" append-to-body>
      <MapSelector ref="mapSelectorRef" @select="handleMapSelect" />
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="mapDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="confirmMapSelection">确 定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Bank">
import { listBank, getBank, delBank, addBank, updateBank } from "@/api/service/bank"
import { regionData } from 'element-china-area-data';
import { areaList, getAreaList, cityOptions, regionOptions, handleProvinceChange, handleCityChange, cascaderProps, organizationOptions, allOrganizations, getOrganizationList, getParentOrgName } from "@/api/common";

// 导入地图选择器组件
import MapSelector from '@/components/MapSelector/index.vue'

const { proxy } = getCurrentInstance()
const { rest_time, fee_attribute, bank_type, scan_flag, bank_status } = proxy.useDict('rest_time', 'fee_attribute', 'bank_type', 'scan_flag', 'bank_status')

const bankList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const daterangeOnlineDate = ref([])
const daterangeOfflineDate = ref([])

// 地图对话框相关
const mapDialogVisible = ref(false)
const mapSelectorRef = ref(null)

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    bankCode: null,
    bankName: null,
    address: null,
    contactPerson: null,
    contactPhone: null,
    bankType: null,
    status: null,
    areaId: null,
    orgId: null,
    restTime: null,
    scanFlag: null,
    feeAttribute: null,
    onlineDate: null,
    suspendDate: null,
    offlineDate: null,
    coLocationDate: null,
    parentOrgName: null,
    subOrgName: null,
    parentBankId: null,
    locateLat: null,
    locateLng: null,
    restTime: null,
    onlineDate: null,
    offlineDate: null,
    coLocationDate: null,
    parentBankName: null,
    subBankName: null,
    parentBankCode: null,
    subBankCode: null
  },
  rules: {
    bankCode: [
      { required: true, message: "网点编号，唯一不能为空", trigger: "blur" }
    ],
    bankName: [
      { required: true, message: "网点名称不能为空", trigger: "blur" }
    ],
    address: [
      { required: true, message: "网点地址不能为空", trigger: "blur" }
    ],
    bankType: [
      { required: true, message: "网点类型不能为空", trigger: "change" }
    ],
    orgId: [
      { required: true, message: "机构ID，外键关联organization表不能为空", trigger: "blur" }
    ]
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询网点管理列表 */
function getList() {
  loading.value = true
  queryParams.value.params = {}
  if (null != daterangeOnlineDate && '' != daterangeOnlineDate) {
    queryParams.value.params["beginOnlineDate"] = daterangeOnlineDate.value[0]
    queryParams.value.params["endOnlineDate"] = daterangeOnlineDate.value[1]
  }
  if (null != daterangeOfflineDate && '' != daterangeOfflineDate) {
    queryParams.value.params["beginOfflineDate"] = daterangeOfflineDate.value[0]
    queryParams.value.params["endOfflineDate"] = daterangeOfflineDate.value[1]
  }
  listBank(queryParams.value).then(response => {
    // 处理每条记录，根据orgId设置parentOrgName和subOrgName用于展示
    bankList.value = response.rows.map(item => {
      // 从allOrganizations中查找对应的机构信息
      const org = allOrganizations.value.find(org => org.id === item.orgId);
      if (org) {
        // 查找该机构对应的父机构信息
        const parentOrg = allOrganizations.value.find(pOrg => pOrg.id === org.parentOrgId);
        if (parentOrg) {
          // 父机构存在时，机构名称显示父机构名称，二级机构显示机构名称
          item.parentOrgName = parentOrg.orgName;
          item.subOrgName = org.orgName;
        } else {
          // 父机构不存在时，机构名称显示机构名称，没有二级机构
          item.parentOrgName = org.orgName;
          item.subOrgName = "";
        }
      } else {
        // 机构不存在时，机构名称和父机构名称都为空
        item.parentOrgName = "";
        item.subOrgName = "";
      }
      return item;
    });
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    bankCode: null,
    bankName: null,
    shortName: null,
    address: null,
    contactPerson: null,
    contactPhone: null,
    bankType: null,
    status: null,
    areaId: null,
    orgId: null,
    parentBankId: null,
    locateLat: null,
    locateLng: null,
    restTime: null,
    qianAndaKey: null,
    gunCabinetKey: null,
    commCardBank: null,
    scanFlag: null,
    feeAttribute: null,
    otherboxType: null,
    otherboxNum: null,
    appointDeliveryDate: null,
    onlineDate: null,
    suspendDate: null,
    offlineDate: null,
    coLocationDate: null,
    isScanMidbox: null,
    pdaPwd: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    remark: null,
    deleted: null
  }
  proxy.resetForm("bankRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  daterangeOnlineDate.value = []
  daterangeOfflineDate.value = []
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加网点管理"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getBank(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改网点管理"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["bankRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateBank(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        // 这两个字段之后需要在后端新建的时候自动生成
        form.value.bankCode = allOrganizations.value.find(item => item.id == form.value.orgId).orgCode
        form.value.status = 1;
        addBank(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除网点管理编号为"' + _ids + '"的数据项？').then(function () {
    return delBank(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => { })
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('service/bank/export', {
    ...queryParams.value
  }, `bank_${new Date().getTime()}.xlsx`)
}


// 获取经纬度
const getCoordinates = () => {
  mapDialogVisible.value = true
  // 等待对话框打开后再初始化地图
  setTimeout(() => {
    if (mapSelectorRef.value) {
      mapSelectorRef.value.open()
    }
  }, 100)
}

// 处理地图选择事件
const handleMapSelect = (location) => {
  // 更新表单中的经度和纬度
  form.value.locateLat = location.lat
  form.value.locateLng = location.lng

  // 关闭地图对话框
  mapDialogVisible.value = false
}

// 确认地图选择
const confirmMapSelection = () => {
  if (mapSelectorRef.value) {
    mapSelectorRef.value.confirmSelection()
  }
}

getOrganizationList()
getAreaList()
getList()
</script>

<!-- 全局设置el-input宽度 -->
<style scoped>
:deep(.el-input),
:deep(.el-select .el-input) {
  width: 215px;
  box-sizing: border-box;
}
</style>